<template>
  <div class="mui-numbox" data-numbox-min="1">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input id="test" class="mui-input-numbox" type="number" value="1" @change="changeNum" ref="num"/>
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from '../../assets/mui/js/mui'
export default {
    data(){
        return{
            
        }
    },
    mounted(){
         // 初始化数字选择框组件
        mui(".mui-numbox").numbox();
    },
    props:["max"],
    watch:{
      // 监听max,有新的值立即把最大值设置新的值
      max:function(newVal,oldVal){
        mui(".mui-numbox").numbox().setOption('max',newVal);
      }
    },
    methods:{
      changeNum(){
        // 每当数据修改时，把value的值传给父组件
        this.$emit('getNum',parseInt(this.$refs.num.value));
      }
    }
};
</script>

<style lang="scss" scoped>
.mui-numbox{
  touch-action: none;
}
</style>